// components/activity-publish-success/index.js
import componentBehavior from '../../../behaviors/component';
import { COMPONENT_OPTIONS } from '../../../constants/common';

Component({
    behaviors: [componentBehavior],
    options: {
        ...COMPONENT_OPTIONS,
    },
    properties: {
        show: {
            type: Boolean,
            value: false,
        },
        activityInfo: {
            type: Object,
            value: {},
        },
    },
    observers: {
        'activityInfo': function (info) {
            if (info) {
                let timeFormat;
                const time = info.ended - Date.now();
                if (time > 24 * 60 * 60 * 1000) {
                    timeFormat = 'DD天HH小时';
                } else if (time <= 24 * 60 * 60 * 1000 && time > 60 * 60 * 1000) {
                    timeFormat = 'HH小时mm分';
                } else {
                    timeFormat = 'mm分';
                }
                this.setData({ time, timeFormat, info });
            }
        },
    },
    data: {
        info: {},
        timeFormat: '',
        time: 0,
    },
    methods: {
        handleClose() {
            this.setData({
                show: false,
            });
        },
        handleConfirm() {
            this.handleClose();
            this.triggerEvent('confirm');
        },
    }
})
